package controllers

import (
	"fmt"
	"io/ioutil"
	"net/url"
)

func (c *StaticController) GetVue() {
	uri := c.Ctx.Request.RequestURI
	b, err := ioutil.ReadFile("./views" + uri) // just pass the file name
	if err != nil {
		fmt.Print(err)
	}
	c.Ctx.WriteString(string(b))
}

func (c *StaticController) GetTpl() {
	if c.Ctx.Input.Param(":filename") == "register.html" {
		c.TplName = "register.html"
		return
	}
	username, _ := url.QueryUnescape(c.Ctx.GetCookie("username"))
	if username == "" {
		c.TplName = "signin.html"
		return
	}
	uri := c.Ctx.Input.Param(":filename")
	b, err := ioutil.ReadFile("./views/" + uri) // just pass the file name
	if err != nil {
		fmt.Print(err)
	}
	c.Ctx.WriteString(string(b))
}

func (c *StaticController) GetCss() {
	uri := c.Ctx.Request.RequestURI
	b, err := ioutil.ReadFile("./static/css" + uri) // just pass the file name
	if err != nil {
		fmt.Print(err)
	}
	c.Ctx.WriteString(string(b))
}

func (c *StaticController) GetPdf() {
	pdf := c.Ctx.Input.Param(":pdf")
	pdf_decode, _ := url.QueryUnescape(pdf)
	fmt.Println(pdf_decode)
	b, err := ioutil.ReadFile("./static/css/" + pdf_decode) // just pass the file name
	if err != nil {
		fmt.Print(err)
	}
	c.Ctx.WriteString(string(b))
}

func (c *StaticController) GetJs() {
	uri := c.Ctx.Request.RequestURI
	b, err := ioutil.ReadFile("./static/js" + uri) // just pass the file name
	if err != nil {
		fmt.Print(err)
	}
	c.Ctx.WriteString(string(b))
}

func (c *StaticController) GetFont() {
	uri := c.Ctx.Request.RequestURI
	b, err := ioutil.ReadFile("./static/font" + uri) // just pass the file name
	if err != nil {
		fmt.Print(err)
	}
	c.Ctx.WriteString(string(b))
}
